﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ExtensionsLib.Dictionary
{


    public static class DictionaryExtensionsInclude
    {
        
        /// <summary>
        /// 
        /// </summary>
        /// <param name="self"></param>
        /// <param name="self"></param>
        /// <param name="replacingAllowed"></param>
        public static void Include<TKey, TValue>(this IDictionary<TKey, TValue> self, IDictionary<TKey, TValue> dictionary, bool replacingAllowed)
        {
            foreach (KeyValuePair<TKey, TValue> item in dictionary)
            {
                if (false == self.ContainsKey(item.Key))
                {
                    self.Add(item);
                }
                else
                {
                    if (replacingAllowed)
                    {
                        self[item.Key] = item.Value;
                    }
                    else
                    {
                        string key = item.Key != null ? item.Key.ToString() : "null";
                        throw new Exception("The key " + key + " already exists!");
                    }
                }
            }
        }


        /// <summary>
        /// 
        /// </summary>
        /// <typeparam name="TKey"></typeparam>
        /// <typeparam name="TValue"></typeparam>
        /// <param name="self"></param>
        /// <param name="self"></param>
        public static void Include<TKey, TValue>(this IDictionary<TKey, TValue> self, IDictionary<TKey, TValue> dictionary)
        {
            self.Include<TKey, TValue>(dictionary, false);
        }




    }
}


 